﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DrinkTest.Question;

namespace DrinkTest.Answer
{
    class Effie:IDrinkTest
    {
        public struct myItem
        {
            public int sa;
            public int ta;
        }

        public long GetSumSat(int[] S, int[] A)
        {
            int tempt = 0;
            long temps = 0;
            if (S.Length != A.Length)
                return 0;
           List<myItem> mylist = new List<myItem>();
            
            for (int i=0; i<A.Length; i++)
            {
                myItem item = new myItem();
                item.sa = S[i];
                item.ta = A[i];
                mylist.Add(item);
            }
           List<myItem> sortedlist = new List<myItem>();
           sortedlist = ListSort(mylist);
           foreach (myItem item in sortedlist)
           {
               int m=0;
               m=100-tempt;
               if (m > item.ta)
                   m = item.ta;
               if (tempt + m <= 100)
               {
                   temps += item.sa * m;
                   tempt += m;
               }
           }
           if (tempt < 100)
               return -1;
           else
               return temps;
        }
       
        public static List<myItem> ListSort(List<myItem> MyList)
        {
            myItem tempitem = new myItem();

            for (int i = 0; i < MyList.Count; i++)
            {
                for (int j = i; j < MyList.Count; j++)
                {
                    if (MyList[i].sa < MyList[j].sa)
                    {
                        tempitem = MyList[i];

                        MyList[i] = MyList[j];

                        MyList[j] = tempitem;
   
                    }
                }
     
            }
            return MyList;
        }
    }
}
